package leetcode;

import java.util.Arrays;

public class twelve {
    public static int minOperations(int[] nums, int x) {
        int n=nums.length;
        int sum= Arrays.stream(nums).sum();
        int target=sum-x;
        int max=0;
        if(target==0){
            return n;
        }
        if(target<0){
            return -1;
        }
        for(int i=0;i<n;i++){
            int sum1=0;
            for(int j=i;j<n;j++){
                sum1+=nums[j];
                if(sum1>=target) {
                    if (sum1 == target) {
                        max = Math.max(max, j - i + 1);
                        //当等于max时候，继续寻找，最大的长度,不用break
                        break;
                    }
                    if(sum1>target){
                        break;
                    }
                }
            }
        }
        if(n-max==n){
            return -1;
        }
        return n-max;

    }

    public static void main(String[] args) {
        int[] array={8828,9581,49,9818,9974,9869,9991,10000,10000,10000,9999,9993,9904,8819,1231,6309};
        int i = minOperations(array, 134365);
        System.out.println(i);

    }
}
